From 581974957fd4ebdaaac1d7438d999316a89a9edf Mon Sep 17 00:00:00 2001
From: Stephen Paul Weber <singpolyma@singpolyma.net>
Date: Thu, 3 Feb 2022 21:43:20 -0500
Subject: [PATCH] Setup for bootstrap by esbuild

---
 Jakefile.js                          | 112 +++++----------------------
 scripts/processDiagnosticMessages.ts |  41 ++++++----
 src/compiler/checker.ts              |  13 ++--
 3 files changed, 52 insertions(+), 114 deletions(-)

diff --git a/Jakefile.js b/Jakefile.js
index 5d85a4e74f..985e44a880 100644
--- a/Jakefile.js
+++ b/Jakefile.js
@@ -6,8 +6,6 @@ var fs = require("fs");
 var os = require("os");
 var path = require("path");
 var child_process = require("child_process");
-var fold = require("travis-fold");
-var ts = require("./lib/typescript");
 
 // Variables
 var compilerDirectory = "src/compiler/";
@@ -59,23 +57,15 @@ function reportDiagnostics(diagnostics) {
 /** @param jsonPath {string} */
 function readJson(jsonPath) {
     const jsonText = fs.readFileSync(jsonPath, "utf8");
-    const result = ts.parseConfigFileTextToJson(jsonPath, jsonText);
-    if (result.error) {
-        reportDiagnostics([result.error]);
-        throw new Error("An error occurred during parse.");
-    }
-    return result.config;
+    const result = eval("(" + jsonText + ")");
+    return result;
 }
 
 /** @param configPath {string} */
 function filesFromConfig(configPath) {
     const config = readJson(configPath);
-    const configFileContent = ts.parseJsonConfigFileContent(config, ts.sys, path.dirname(configPath));
-    if (configFileContent.errors && configFileContent.errors.length) {
-        reportDiagnostics(configFileContent.errors);
-        throw new Error("An error occurred during parse.");
-    }
-    return configFileContent.fileNames;
+    const configDir = path.dirname(configPath);
+    return config.files.map(function(file) { return configDir + "/" + file; });
 }
 
 function toNs(diff) {
@@ -83,21 +73,11 @@ function toNs(diff) {
 }
 
 function mark() {
-    if (!fold.isTravis()) return;
-    var stamp = process.hrtime();
-    var id = Math.floor(Math.random() * 0xFFFFFFFF).toString(16);
-    console.log("travis_time:start:" + id + "\r");
-    return {
-        stamp: stamp,
-        id: id
-    };
+  return;
 }
 
 function measure(marker) {
-    if (!fold.isTravis()) return;
-    var diff = process.hrtime(marker.stamp);
-    var total = [marker.stamp[0] + diff[0], marker.stamp[1] + diff[1]];
-    console.log("travis_time:end:" + marker.id + ":start=" + toNs(marker.stamp) + ",finish=" + toNs(total) + ",duration=" + toNs(diff) + "\r");
+  return;
 }
 
 function removeConstModifierFromEnumDeclarations(text) {
@@ -197,7 +177,7 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts
         var startCompileTime = mark();
         opts = opts || {};
         var compilerPath = useBuiltCompiler ? builtLocalCompiler : LKGCompiler;
-        var options = "--noImplicitAny --noImplicitThis --alwaysStrict --noEmitOnError";
+        var options = "--noImplicitThis --alwaysStrict --noEmitOnError";
         if (opts.types) {
             options += " --types " + opts.types.join(",");
         }
@@ -249,7 +229,7 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts
             options += " --lib " + opts.lib;
         }
         else {
-            options += " --lib es5";
+            options += " --lib es5,es2015.collection";
         }
         options += " --noUnusedLocals --noUnusedParameters";
 
@@ -257,15 +237,7 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts
         cmd = cmd + sources.join(" ");
         console.log(cmd + "\n");
 
-        var ex = jake.createExec([cmd]);
-        // Add listeners for output and error
-        ex.addListener("stdout", function (output) {
-            process.stdout.write(output);
-        });
-        ex.addListener("stderr", function (error) {
-            process.stderr.write(error);
-        });
-        ex.addListener("cmdEnd", function () {
+        var ex = child_process.execSync(cmd);
             if (!useDebugMode && prefixes && fs.existsSync(outFile)) {
                 for (var i in prefixes) {
                     prependFile(prefixes[i], outFile);
@@ -277,15 +249,7 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts
             }
 
             measure(startCompileTime);
-            complete();
-        });
-        ex.addListener("error", function () {
-            fs.unlinkSync(outFile);
-            fail("Compilation of " + outFile + " unsuccessful");
-            measure(startCompileTime);
-        });
-        ex.run();
-    }, { async: true });
+    }, { async: false });
 }
 
 // Prerequisite task for built directory and library typings
@@ -339,22 +303,11 @@ compileFile(generateLocalizedDiagnosticMessagesJs,
     /*useBuiltCompiler*/ false, { noOutFile: true, types: ["node", "xml2js"] });
 
 // Localize diagnostics
-file(generatedLCGFile, [generateLocalizedDiagnosticMessagesJs, diagnosticInfoMapTs, generatedDiagnosticMessagesJSON], function () {
+file(generatedLCGFile, [], function () {
     var cmd = host + " " + generateLocalizedDiagnosticMessagesJs + " " + lclDirectory + " " + builtLocalDirectory + " " + generatedDiagnosticMessagesJSON;
     console.log(cmd);
-    var ex = jake.createExec([cmd]);
-    // Add listeners for output and error
-    ex.addListener("stdout", function (output) {
-        process.stdout.write(output);
-    });
-    ex.addListener("stderr", function (error) {
-        process.stderr.write(error);
-    });
-    ex.addListener("cmdEnd", function () {
-        complete();
-    });
-    ex.run();
-}, { async: true });
+    child_process.execSync(cmd);
+}, { async: false });
 
 task("localize", [generatedLCGFile]);
 
@@ -378,37 +331,15 @@ file(buildProtocolDts, [buildProtocolTs, buildProtocolJs, typescriptServicesDts]
 
     var cmd = host + " " + buildProtocolJs + " "+ protocolTs + " " + typescriptServicesDts + " " + buildProtocolDts;
     console.log(cmd);
-    var ex = jake.createExec([cmd]);
-    // Add listeners for output and error
-    ex.addListener("stdout", function (output) {
-        process.stdout.write(output);
-    });
-    ex.addListener("stderr", function (error) {
-        process.stderr.write(error);
-    });
-    ex.addListener("cmdEnd", function () {
-        complete();
-    });
-    ex.run();
-}, { async: true });
+    child_process.execSync(cmd);
+}, { async: false });
 
+console.log(diagnosticInfoMapTs, [processDiagnosticMessagesJs, diagnosticMessagesJson]);
 // The generated diagnostics map; built for the compiler and for the 'generate-diagnostics' task
 file(diagnosticInfoMapTs, [processDiagnosticMessagesJs, diagnosticMessagesJson], function () {
     var cmd = host + " " + processDiagnosticMessagesJs + " " + diagnosticMessagesJson;
-    console.log(cmd);
-    var ex = jake.createExec([cmd]);
-    // Add listeners for output and error
-    ex.addListener("stdout", function (output) {
-        process.stdout.write(output);
-    });
-    ex.addListener("stderr", function (error) {
-        process.stderr.write(error);
-    });
-    ex.addListener("cmdEnd", function () {
-        complete();
-    });
-    ex.run();
-}, { async: true });
+    child_process.execSync(cmd);
+}, { async: false });
 
 file(builtGeneratedDiagnosticMessagesJSON, [generatedDiagnosticMessagesJSON], function () {
     if (fs.existsSync(builtLocalDirectory)) {
@@ -575,12 +506,10 @@ task("lssl", [tsserverLibraryFile, tsserverLibraryDefinitionFile, typesMapOutput
 
 desc("Emit the start of the build fold");
 task("build-fold-start", [], function () {
-    if (fold.isTravis()) console.log(fold.start("build"));
 });
 
 desc("Emit the end of the build fold");
 task("build-fold-end", [], function () {
-    if (fold.isTravis()) console.log(fold.end("build"));
 });
 
 // Local target to build the compiler and services
@@ -642,8 +571,8 @@ task("generate-spec", [specMd]);
 
 // Makes a new LKG. This target does not build anything, but errors if not all the outputs are present in the built/local directory
 desc("Makes a new LKG out of the built js files");
-task("LKG", ["clean", "release", "local"].concat(libraryTargets), function () {
-    var expectedFiles = [tscFile, servicesFile, serverFile, nodePackageFile, nodeDefinitionsFile, standaloneDefinitionsFile, tsserverLibraryFile, tsserverLibraryDefinitionFile, cancellationTokenFile, typingsInstallerFile, buildProtocolDts, watchGuardFile].
+task("LKG", ["clean", "release", "local"], function () {
+    var expectedFiles = [tscFile, servicesFile, serverFile, nodePackageFile, nodeDefinitionsFile, standaloneDefinitionsFile, tsserverLibraryFile, tsserverLibraryDefinitionFile, cancellationTokenFile, typingsInstallerFile, buildProtocolDts, watchGuardFile, typesMapOutputPath].
         concat(libraryTargets).
         concat(localizationTargets);
     var missingFiles = expectedFiles.filter(function (f) {
@@ -718,7 +647,6 @@ function exec(cmd, completeHandler, errorHandler) {
     ex.run();
 }
 
-const del = require("del");
 function cleanTestDirs() {
     // Clean the local baselines directory
     if (fs.existsSync(localBaseline)) {
diff --git a/scripts/processDiagnosticMessages.ts b/scripts/processDiagnosticMessages.ts
index 848a60cfb4..750ae75660 100644
--- a/scripts/processDiagnosticMessages.ts
+++ b/scripts/processDiagnosticMessages.ts
@@ -7,30 +7,39 @@ interface DiagnosticDetails {
 
 type InputDiagnosticMessageTable = ts.Map<DiagnosticDetails>;
 
-function main(): void {
-    const sys = ts.sys;
-    if (sys.args.length < 1) {
-        sys.write("Usage:" + sys.newLine);
-        sys.write("\tnode processDiagnosticMessages.js <diagnostic-json-input-file>" + sys.newLine);
-        return;
+var fs = require("fs");
+var path = require("path");
+
+// Copied from src/compiler/core.ts
+function createMapFromTemplate(template?: any): any {
+    const map: any = new Map();
+
+    // Copies keys/values from template. Note that for..in will not throw if
+    // template is undefined, and instead will just exit the loop.
+    for (const key in template) {
+        if (Object.prototype.hasOwnProperty.call(template, key)) {
+            map.set(key, template[key]);
+        }
     }
 
+    return map;
+}
+
+function main(): void {
     function writeFile(fileName: string, contents: string) {
-        const inputDirectory = ts.getDirectoryPath(inputFilePath);
-        const fileOutputPath = ts.combinePaths(inputDirectory, fileName);
-        sys.writeFile(fileOutputPath, contents);
+        const inputDirectory = path.dirname(inputFilePath);
+        const fileOutputPath = inputDirectory + "/" + fileName;
+        fs.writeFileSync(fileOutputPath, contents);
     }
 
-    const inputFilePath = sys.args[0].replace(/\\/g, "/");
-    const inputStr = sys.readFile(inputFilePath);
+    const inputFilePath = process.argv.pop().replace(/\\/g, "/");
+    const inputStr = fs.readFileSync(inputFilePath);
 
     const diagnosticMessagesJson: { [key: string]: DiagnosticDetails } = JSON.parse(inputStr);
 
-    const diagnosticMessages: InputDiagnosticMessageTable = ts.createMapFromTemplate(diagnosticMessagesJson);
+    const diagnosticMessages: InputDiagnosticMessageTable = createMapFromTemplate(diagnosticMessagesJson);
 
-    const outputFilesDir = ts.getDirectoryPath(inputFilePath);
-    const thisFilePathRel = ts.getRelativePathToDirectoryOrUrl(outputFilesDir, sys.getExecutingFilePath(),
-        sys.getCurrentDirectory(), ts.createGetCanonicalFileName(sys.useCaseSensitiveFileNames), /* isAbsolutePathAnUrl */ false);
+    const thisFilePathRel = ".";
 
     const infoFileOutput = buildInfoFileOutput(diagnosticMessages, "./diagnosticInformationMap.generated.ts", thisFilePathRel);
     checkForUniqueCodes(diagnosticMessages);
@@ -112,4 +121,4 @@ function convertPropertyName(origName: string): string {
     return result;
 }
 
-main();
\ No newline at end of file
+main();
diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts
index 3f8a22ffa8..bae13967b7 100644
--- a/src/compiler/checker.ts
+++ b/src/compiler/checker.ts
@@ -21884,6 +21884,13 @@ namespace ts {
         }
 
         function checkExportsOnMergedDeclarations(node: Node): void {
+            const enum DeclarationSpaces {
+                None = 0,
+                ExportValue = 1 << 0,
+                ExportType = 1 << 1,
+                ExportNamespace = 1 << 2,
+            }
+
             if (!produceDiagnostics) {
                 return;
             }
@@ -21947,12 +21954,6 @@ namespace ts {
                 }
             }
 
-            const enum DeclarationSpaces {
-                None = 0,
-                ExportValue = 1 << 0,
-                ExportType = 1 << 1,
-                ExportNamespace = 1 << 2,
-            }
             function getDeclarationSpaces(decl: Declaration): DeclarationSpaces {
                 let d = decl as Node;
                 switch (d.kind) {
-- 
2.30.2

